package wsepForum.common.elements;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.compass.annotations.*;


/**
 * 
 * @author Ofir Tam & Ori Ossmy
 *
 */
public abstract class AForumElement {

	/*****************************
	 * MEMBERS                   *
	 *****************************/
	/**
	 * 
	 */
	public static enum ForumElementType {SECTION, TOPIC, MESSAGE};

	/**
	 * 
	 */
	protected int elementID;
	
	/**
	 * 
	 */
	protected String headLine;
	
	/**
	 * the element that contains the current element
	 */
	protected int parentID;
	
	/**
	 * 
	 */
	protected String timeStamp ;
	
	
	
	/*****************************
	 * CONSTRUCTOR               *
	 *****************************/
	protected AForumElement() {
		
	}
	
	/**
	 * 
	 * @param headLine
	 * @param parentID
	 */
	public AForumElement(String headLine, int parentID) {
		this.elementID = -1;
		this.headLine = headLine;
		this.timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date());
		this.parentID = parentID;
	}
	
	
	/*****************************
	 * METHODS                   *
	 *****************************/
	/**
	 * 
	 */
	public abstract ForumElementType elementIdetitity();

	
	@SearchableId
	public int getElementID() {
		return this.elementID;
	}
	
	
	/**
	 * 
	 * @param elementID
	 */
	public int setElementID(int elementID) {
		if (this.elementID==-1) {
			this.elementID = elementID;
			return 1;
		}
		return 0;
	}	
	
	
	/**
	 * 
	 * @return
	 */
	public int getParentID() {
		return this.parentID;
	}

	
	/**
	 * 
	 * @param parentID
	 */
	public void setParentID(int parentID){
		this.parentID = parentID;
	}
	

	/**
	 * 
	 * @return
	 */
	@SearchableProperty(name = "contents")
	public String getHeadLine() {
		return this.headLine;
	}
	

	/**
	 * 
	 * @param headLine
	 */
	public void setHeadLine(String headLine) {
		this.headLine = headLine;
	}	
	
	
	/**
	 * 
	 * @return
	 */
	@SearchableProperty(name = "date")
	public String getTimeStamp() {
		return this.timeStamp;
	}

	
	/**
	 * 
	 * @param timeStamp
	 */
	public void setTimeStamp(String timeStamp) {
		this.timeStamp = timeStamp;
	}
	
}
